package com.ddwl.order.service;

import com.ddwl.common.constant.MobileConfigEnum;
import com.ddwl.common.constant.StatisticsEnum;
import com.ddwl.common.feign.api.DataApi;
import com.ddwl.common.feign.api.GateApi;
import com.ddwl.common.feign.api.MessageApi;
import com.ddwl.common.feign.api.UserApi;
import com.ddwl.common.util.BeanConverUtils;
import com.ddwl.order.dao.OrderInfoDao;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.gate.LoanSentSmsFlowBo;
import com.ddwl.schema.bo.gate.MobileRechargeRecordPageBo;
import com.ddwl.schema.bo.gate.SentSmsFlowDto;
import com.ddwl.schema.bo.order.QueryOrderListBo;
import com.ddwl.schema.bo.user.UserSearchBo;
import com.ddwl.schema.util.DateUtil;
import com.ddwl.schema.vo.gate.MobileRechargeRecordVo;
import com.ddwl.schema.vo.order.*;
import com.ddwl.schema.vo.user.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 数据统计
 * @author wenbin
 */
@Service
@RefreshScope
@Slf4j
public class StatisticsServer{


    @Resource
    private OrderInfoDao orderInfoDao;
    @Resource
    private GateApi gateApi;
    @Resource
    private MessageApi messageApi;
    @Resource
    private UserApi userApi;
    @Resource
    private DataApi dataApi;
    /**
     * 小程序
     */
    private static final String productMall="mall";
    /**
     * app
     */
    private static final String productFenxiao="fenxiao";


    @Deprecated
    public StatisticsVo getStatistics() {

        StatisticsVo statisticsVo=new StatisticsVo();
        /**
         * 1，每日注册用户数（区分小程序和app）
         */
        List<UserVo> userVos = queryStatisticsUser();
        List<StatisticsUserVo> statisticsUsers=new ArrayList<>();
        //小程序
        StatisticsUserVo statisticsUserVo=new StatisticsUserVo();
        statisticsUserVo.setPlatform(0);
        if (!CollectionUtils.isEmpty(userVos)){
            List<UserVo> list = userVos.stream().filter(o -> o.getType() == 0).collect(Collectors.toList());
            statisticsUserVo.setRegisterUserCount(list.size());
        }else {
            statisticsUserVo.setRegisterUserCount(0);
        }
        statisticsUsers.add(statisticsUserVo);
        //app
        StatisticsUserVo statisticsUserVo2=new StatisticsUserVo();
        statisticsUserVo2.setPlatform(1);
        if (!CollectionUtils.isEmpty(userVos)){
            List<UserVo> list2 = userVos.stream().filter(o -> o.getType() == 1).collect(Collectors.toList());
            statisticsUserVo2.setRegisterUserCount(list2.size());
        }else {
            statisticsUserVo2.setRegisterUserCount(0);
        }
        statisticsUsers.add(statisticsUserVo2);
        statisticsVo.setStatisticsUsers(statisticsUsers);

        /**
         * 2，每日短信发送条数
         */
        List<LoanSentSmsFlowBo> loanSentSmsFlowBos = queryStatisticsSms();
        statisticsVo.setSmsCount(loanSentSmsFlowBos.size());


        /**
         * 3，每日成交金额,每日成交订单数
         */
        List<MobileRechargeRecordVo> mobileRechargeRecordVos = queryStatisticsMobileOrder();
        List<OrderInfoVo> orderInfoVos = queryStatisticsOrder();
        //1)支付宝+app+商品
        List<OrderInfoVo> alipayAppOrders = orderInfoVos.stream().filter(o -> o.getPaymentType().equals("1") && o.getProduct().equals(productFenxiao)).collect(Collectors.toList());
        //2)支付宝+app+话费
        List<MobileRechargeRecordVo> alipayAppMobiles = mobileRechargeRecordVos.stream().filter(o -> o.getPayType()==1).collect(Collectors.toList());
        //3)微信+app+商品
        List<OrderInfoVo> wxpayAppOrders = orderInfoVos.stream().filter(o -> o.getPaymentType().equals("0") && o.getProduct().equals(productFenxiao)).collect(Collectors.toList());
        //4)微信+app+话费
        List<MobileRechargeRecordVo> wxpayAppMobiles = mobileRechargeRecordVos.stream().filter(o -> o.getPayType()==0).collect(Collectors.toList());
        //5)微信+小程序+商品
        List<OrderInfoVo> wxpayMallOrders = orderInfoVos.stream().filter(o -> o.getPaymentType().equals("0") && o.getProduct().equals(productMall)).collect(Collectors.toList());
        //6)微信+小程序+话费(目前不支持)

        //3，每日成交金额（区分支付宝，微信，区分小程序，app，区分商品，和话费充值）
        List<StatisticsAmountVo> statisticsAmounts=new ArrayList<>();
        //1)支付宝+app+商品
        StatisticsAmountVo statisticsAmountVo=new StatisticsAmountVo();
        statisticsAmountVo.setPayType(1);
        statisticsAmountVo.setOrderStyle(0);
        statisticsAmountVo.setPlatform(1);
        if (!CollectionUtils.isEmpty(alipayAppOrders)){
            BigDecimal reduce = alipayAppOrders.stream().map(OrderInfoVo::getPayAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
            statisticsAmountVo.setTotalAmounts(reduce);
        }else {
            statisticsAmountVo.setTotalAmounts(BigDecimal.ZERO);
        }
        statisticsAmounts.add(statisticsAmountVo);
        //2)支付宝+app+话费
        StatisticsAmountVo statisticsAmountVo2=new StatisticsAmountVo();
        statisticsAmountVo2.setPayType(1);
        statisticsAmountVo2.setOrderStyle(1);
        statisticsAmountVo2.setPlatform(1);
        if (!CollectionUtils.isEmpty(alipayAppMobiles)){
            BigDecimal reduce = alipayAppMobiles.stream().map(MobileRechargeRecordVo::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
            statisticsAmountVo2.setTotalAmounts(reduce);
        }else {
            statisticsAmountVo2.setTotalAmounts(BigDecimal.ZERO);
        }
        statisticsAmounts.add(statisticsAmountVo2);
        //3)微信+app+商品
        StatisticsAmountVo statisticsAmountVo3=new StatisticsAmountVo();
        statisticsAmountVo3.setPayType(0);
        statisticsAmountVo3.setOrderStyle(0);
        statisticsAmountVo3.setPlatform(1);
        if (!CollectionUtils.isEmpty(wxpayAppOrders)){
            BigDecimal reduce = wxpayAppOrders.stream().map(OrderInfoVo::getPayAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
            statisticsAmountVo3.setTotalAmounts(reduce);
        }else {
            statisticsAmountVo3.setTotalAmounts(BigDecimal.ZERO);
        }
        statisticsAmounts.add(statisticsAmountVo3);
        //4)微信+app+话费
        StatisticsAmountVo statisticsAmountVo4=new StatisticsAmountVo();
        statisticsAmountVo4.setPayType(0);
        statisticsAmountVo4.setOrderStyle(1);
        statisticsAmountVo4.setPlatform(1);
        if (!CollectionUtils.isEmpty(wxpayAppMobiles)){
            BigDecimal reduce = wxpayAppMobiles.stream().map(MobileRechargeRecordVo::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
            statisticsAmountVo4.setTotalAmounts(reduce);
        }else {
            statisticsAmountVo4.setTotalAmounts(BigDecimal.ZERO);
        }
        statisticsAmounts.add(statisticsAmountVo4);
        //5)微信+小程序+商品
        StatisticsAmountVo statisticsAmountVo5=new StatisticsAmountVo();
        statisticsAmountVo5.setPayType(0);
        statisticsAmountVo5.setOrderStyle(0);
        statisticsAmountVo5.setPlatform(0);
        if (!CollectionUtils.isEmpty(wxpayMallOrders)){
            BigDecimal reduce = wxpayMallOrders.stream().map(OrderInfoVo::getPayAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
            statisticsAmountVo5.setTotalAmounts(reduce);
        }else {
            statisticsAmountVo5.setTotalAmounts(BigDecimal.ZERO);
        }
        statisticsAmounts.add(statisticsAmountVo5);
        statisticsVo.setStatisticsAmounts(statisticsAmounts);




        /**
         * 4，每日成交订单数（区分商品订单，话费充值订单）
         */
        List<StatisticsOrderVo> statisticsOrders=new ArrayList<>();
        //商品
        int i = alipayAppOrders.size() + wxpayAppOrders.size() + wxpayMallOrders.size();
        StatisticsOrderVo statisticsOrderVo=new StatisticsOrderVo();
        statisticsOrderVo.setOrderCount(i);
        statisticsOrderVo.setOrderStyle(0);
        statisticsOrders.add(statisticsOrderVo);
        //话费
        int j = alipayAppMobiles.size() + wxpayAppMobiles.size();
        StatisticsOrderVo statisticsOrderVo2=new StatisticsOrderVo();
        statisticsOrderVo2.setOrderCount(j);
        statisticsOrderVo2.setOrderStyle(1);
        statisticsOrders.add(statisticsOrderVo2);
        statisticsVo.setStatisticsOrders(statisticsOrders);

        /**
         * //5,   每日活跃用户数（区分小程序和app，区分正常用户，访客，根据当日调用接口数据来统计）
         */

        return statisticsVo;
    }

    public StatisticsVo getStatisticsNew() {

        StatisticsVo statisticsVo=new StatisticsVo();
        /**
         * 1，每日注册用户数（区分小程序和app）
         * 每日活跃用户数（区分小程序和app，区分正常用户，访客）
         */
        List<StatisticsUserVo> statisticsUserVos = queryStatisticsUserNew();
        List<StatisticsUserVo> statisticsUserVos1 = queryActiveUserNew();
        List<StatisticsUserVo> statisticsUsers=new ArrayList<>();
        //小程序
        StatisticsUserVo statisticsUserVo=new StatisticsUserVo();
        statisticsUserVo.setPlatform(0);
        statisticsUserVo.setRegisterUserCount(0);
        if (!CollectionUtils.isEmpty(statisticsUserVos)){
            statisticsUserVos.stream().forEach(o -> {
                if (o.getPlatform()==0){
                    statisticsUserVo.setRegisterUserCount(o.getRegisterUserCount());
                }
            });
        }
        if(!CollectionUtils.isEmpty(statisticsUserVos1)){
            statisticsUserVos1.stream().forEach(o -> {
                if (o.getPlatform()==0){
                    statisticsUserVo.setCustomerCount(o.getCustomerCount());
                    statisticsUserVo.setActiveUserCount(o.getActiveUserCount());
                }
            });
        }else {
            statisticsUserVo.setCustomerCount(0);
            statisticsUserVo.setActiveUserCount(0);
        }
        statisticsUsers.add(statisticsUserVo);
        //app
        StatisticsUserVo statisticsUserVo2=new StatisticsUserVo();
        statisticsUserVo2.setPlatform(1);
        statisticsUserVo2.setRegisterUserCount(0);
        if (!CollectionUtils.isEmpty(statisticsUserVos)){
            statisticsUserVos.stream().forEach(o -> {
                if (o.getPlatform()==1){
                    statisticsUserVo2.setRegisterUserCount(o.getRegisterUserCount());
                }
            });

        }
        if (!CollectionUtils.isEmpty(statisticsUserVos1)){
            statisticsUserVos1.stream().forEach(o -> {
                if (o.getPlatform()==1){
                    statisticsUserVo2.setActiveUserCount(o.getActiveUserCount());
                    statisticsUserVo2.setCustomerCount(o.getCustomerCount());
                }
            });
        }else {
            statisticsUserVo2.setActiveUserCount(0);
            statisticsUserVo2.setCustomerCount(0);
        }
        statisticsUsers.add(statisticsUserVo2);
        statisticsVo.setStatisticsUsers(statisticsUsers);

        /**
         * 2，每日短信发送条数
         */
        statisticsVo.setSmsCount(queryStatisticsSmsNew()==null?0:queryStatisticsSmsNew());


        /**
         * 3，每日成交金额
         */
        List<StatisticsAmountVo> statisticsAmountMobiles = queryStatisticsMobileAmount();
        List<StatisticsAmountVo> statisticsAmountList = queryOrderSpuListAmount();

        //3，每日成交金额（区分支付宝，微信，区分小程序，app，区分商品，和话费充值）
        List<StatisticsAmountVo> statisticsAmounts=new ArrayList<>();
        //1)支付宝+app+商品
        StatisticsAmountVo statisticsAmountVo=new StatisticsAmountVo();
        statisticsAmountVo.setPayType(1);
        statisticsAmountVo.setOrderStyle(0);
        statisticsAmountVo.setPlatform(1);
        statisticsAmountVo.setTotalAmounts(BigDecimal.ZERO);
        if (!CollectionUtils.isEmpty(statisticsAmountList)){
            statisticsAmountList.stream().forEach(o->{
                if (o.getPlatform()==1&&o.getPayType()==1&&o.getOrderStyle()==0){
                    statisticsAmountVo.setTotalAmounts(o.getTotalAmounts());
                }
            });
        }
        statisticsAmounts.add(statisticsAmountVo);
        //2)支付宝+app+话费
        StatisticsAmountVo statisticsAmountVo2=new StatisticsAmountVo();
        statisticsAmountVo2.setPayType(1);
        statisticsAmountVo2.setOrderStyle(1);
        statisticsAmountVo2.setPlatform(1);
        statisticsAmountVo2.setTotalAmounts(BigDecimal.ZERO);
        if (!CollectionUtils.isEmpty(statisticsAmountMobiles)){
            statisticsAmountMobiles.stream().forEach(o->{
                if (o.getPlatform()==1&&o.getPayType()==1&&o.getOrderStyle()==1){
                    statisticsAmountVo2.setTotalAmounts(o.getTotalAmounts());
                }
            });
        }
        statisticsAmounts.add(statisticsAmountVo2);
        //3)微信+app+商品
        StatisticsAmountVo statisticsAmountVo3=new StatisticsAmountVo();
        statisticsAmountVo3.setPayType(0);
        statisticsAmountVo3.setOrderStyle(0);
        statisticsAmountVo3.setPlatform(1);
        statisticsAmountVo3.setTotalAmounts(BigDecimal.ZERO);
        if (!CollectionUtils.isEmpty(statisticsAmountList)){
            statisticsAmountList.stream().forEach(o->{
                if (o.getPlatform()==1&&o.getPayType()==0&&o.getOrderStyle()==0){
                    statisticsAmountVo3.setTotalAmounts(o.getTotalAmounts());
                }
            });
        }
        statisticsAmounts.add(statisticsAmountVo3);
        //4)微信+app+话费
        StatisticsAmountVo statisticsAmountVo4=new StatisticsAmountVo();
        statisticsAmountVo4.setPayType(0);
        statisticsAmountVo4.setOrderStyle(1);
        statisticsAmountVo4.setPlatform(1);
        statisticsAmountVo4.setTotalAmounts(BigDecimal.ZERO);
        if (!CollectionUtils.isEmpty(statisticsAmountMobiles)){
            statisticsAmountMobiles.stream().forEach(o->{
                if (o.getPlatform()==1&&o.getPayType()==0&&o.getOrderStyle()==1){
                    statisticsAmountVo4.setTotalAmounts(o.getTotalAmounts());
                }
            });
        }
        statisticsAmounts.add(statisticsAmountVo4);
        //5)微信+小程序+商品
        StatisticsAmountVo statisticsAmountVo5=new StatisticsAmountVo();
        statisticsAmountVo5.setPayType(0);
        statisticsAmountVo5.setOrderStyle(0);
        statisticsAmountVo5.setPlatform(0);
        statisticsAmountVo5.setTotalAmounts(BigDecimal.ZERO);
        if (!CollectionUtils.isEmpty(statisticsAmountList)){
            statisticsAmountList.stream().forEach(o->{
                if (o.getPlatform()==0&&o.getPayType()==0&&o.getOrderStyle()==0){
                    statisticsAmountVo5.setTotalAmounts(o.getTotalAmounts());
                }
            });
        }
        statisticsAmounts.add(statisticsAmountVo5);
        statisticsVo.setStatisticsAmounts(statisticsAmounts);




        /**
         * 4，每日成交订单数（区分商品订单，话费充值订单）
         */
        List<StatisticsOrderVo> statisticsOrders=new ArrayList<>();
        //商品
        int i = statisticsAmountList.stream().mapToInt(e-> e.getOrderCount()==null?0:e.getOrderCount()).sum();
        StatisticsOrderVo statisticsOrderVo=new StatisticsOrderVo();
        statisticsOrderVo.setOrderCount(i);
        statisticsOrderVo.setOrderStyle(0);
        statisticsOrders.add(statisticsOrderVo);
        //话费
        int j = statisticsAmountMobiles.stream().mapToInt(e-> e.getOrderCount()==null?0:e.getOrderCount()).sum();
        StatisticsOrderVo statisticsOrderVo2=new StatisticsOrderVo();
        statisticsOrderVo2.setOrderCount(j);
        statisticsOrderVo2.setOrderStyle(1);
        statisticsOrders.add(statisticsOrderVo2);
        statisticsVo.setStatisticsOrders(statisticsOrders);

        return statisticsVo;
    }

    /**
     * 查询话费充值订单
     */
    public List<MobileRechargeRecordVo> queryStatisticsMobileOrder(){
        PageBo<MobileRechargeRecordPageBo> pageBo=new PageBo<>();
        MobileRechargeRecordPageBo bo =new MobileRechargeRecordPageBo();
        bo.setStatus(MobileConfigEnum.RechargeEnum.SUCCESS.getCode());
        bo.setStartTime(DateUtil.getTimesMorning(-1));
        bo.setEndTime(DateUtil.getTimesNight(-1));
        pageBo.setParam(bo);
        pageBo.setPageSize(500);
        List<MobileRechargeRecordVo> rechargeRecordVos = gateApi.page(pageBo).getResult().getData();
        return rechargeRecordVos;
    }

    /**
     * 查询话费充值金额
     */
    public List<StatisticsAmountVo> queryStatisticsMobileAmount(){
        MobileRechargeRecordPageBo bo =new MobileRechargeRecordPageBo();
        bo.setStatus(MobileConfigEnum.RechargeEnum.SUCCESS.getCode());
        bo.setStartTime(DateUtil.getTimesMorning(-1));
        bo.setEndTime(DateUtil.getTimesNight(-1));
        List<StatisticsAmountVo> statisticsAmountVos = gateApi.getAmount(bo).getResult();
        return statisticsAmountVos;
    }

    /**
     * 查询商品订单
     */
    public List<OrderInfoVo> queryStatisticsOrder(){
        QueryOrderListBo bo=new QueryOrderListBo();
        bo.setStartPayTime(DateUtil.getTimesMorning(-1));
        bo.setEndPayTime(DateUtil.getTimesNight(-1));
        List<OrderInfoVo> orderInfoVos = BeanConverUtils.convertBeanList(orderInfoDao.queryOrderSpuList(bo), OrderInfoVo.class);
        return orderInfoVos;
    }

    /**
     * 查询商品金额
     */
    public List<StatisticsAmountVo> queryOrderSpuListAmount(){
        QueryOrderListBo bo=new QueryOrderListBo();
        bo.setStartPayTime(DateUtil.getTimesMorning(-1));
        bo.setEndPayTime(DateUtil.getTimesNight(-1));
        List<StatisticsAmountVo> statisticsAmountVos= orderInfoDao.queryOrderSpuListAmount(bo);
        return statisticsAmountVos;
    }

    /**
     * 查询短信信息
     */
    public List<LoanSentSmsFlowBo> queryStatisticsSms(){
        PageBo<SentSmsFlowDto> pageBo=new PageBo<>();
        SentSmsFlowDto bo=new SentSmsFlowDto();
        bo.setStartTime(DateUtil.getTimesMorning(-1));
        bo.setEndTime(DateUtil.getTimesNight(-1));
        pageBo.setParam(bo);
        pageBo.setPageSize(500);
        List<LoanSentSmsFlowBo> sentSmsFlowBos = messageApi.getSmsPage(pageBo).getResult().getData();
        return sentSmsFlowBos;
    }
    /**
     * 查询短信信息新
     */
    public Integer queryStatisticsSmsNew(){
        SentSmsFlowDto bo=new SentSmsFlowDto();
        bo.setStartTime(DateUtil.getTimesMorning(-1));
        bo.setEndTime(DateUtil.getTimesNight(-1));
        Integer sentSmsFlowCount = messageApi.getSmsCount(bo).getResult();
        return sentSmsFlowCount;
    }

    /**
     * 查询用户信息
     */
    public List<UserVo> queryStatisticsUser(){
        PageBo<UserSearchBo> pageBo=new PageBo<>();
        UserSearchBo bo=new UserSearchBo();
        bo.setBeginDate(DateUtil.getTimesMorning(-1));
        bo.setEndDate(DateUtil.getTimesNight(-1));
        pageBo.setParam(bo);
        pageBo.setPageSize(500);
        List<UserVo> userVos = userApi.getUserPage(pageBo).getResult().getData();
        return userVos;
    }

    /**
     * 查询用户信息新
     */
    public List<StatisticsUserVo> queryStatisticsUserNew(){
        UserSearchBo bo=new UserSearchBo();
        bo.setBeginDate(DateUtil.getTimesMorning(-1));
        bo.setEndDate(DateUtil.getTimesNight(-1));
        List<StatisticsUserVo> statisticsUserVos = userApi.pageUserCount(bo).getResult();
        return statisticsUserVos;
    }

    /**
     * 查询活跃用户信息新
     */
    public List<StatisticsUserVo> queryActiveUserNew(){
        UserSearchBo bo=new UserSearchBo();
        bo.setBeginDate(DateUtil.getTimesMorning(-1));
        bo.setEndDate(DateUtil.getTimesNight(-1));
        List<StatisticsUserVo> statisticsUserVos = dataApi.activeUserCount(bo).getResult();
        return statisticsUserVos;
    }

    public void sentStatisticsMsg() throws Exception {
        StringBuffer message=new StringBuffer();
        StatisticsVo statisticsVo = getStatisticsNew();
        List<StatisticsUserVo> statisticsUsers = statisticsVo.getStatisticsUsers();
        List<StatisticsAmountVo> statisticsAmounts = statisticsVo.getStatisticsAmounts();
        List<StatisticsOrderVo> statisticsOrders = statisticsVo.getStatisticsOrders();

        message
                .append(",用户数据统计:,")
                //小程序:注册用户
                .append(StatisticsEnum.platform.MALL.getName()).append(":")
                .append(StatisticsEnum.UserStyle.REGISTER.getName()).append(":")
                .append(statisticsUsers.stream().filter(o->StatisticsEnum.platform.MALL.getCode()==o.getPlatform())
                        .mapToInt(e-> e.getRegisterUserCount()==null?0:e.getRegisterUserCount()).sum()).append(",")
                //小程序:活跃用户
                .append(StatisticsEnum.platform.MALL.getName()).append(":")
                .append(StatisticsEnum.UserStyle.ACTIVE.getName()).append(":")
                .append(statisticsUsers.stream().filter(o->StatisticsEnum.platform.MALL.getCode()==o.getPlatform())
                        .mapToInt(e-> e.getActiveUserCount()==null?0:e.getActiveUserCount()).sum()).append(",")
                //小程序:游客
                .append(StatisticsEnum.platform.MALL.getName()).append(":")
                .append(StatisticsEnum.UserStyle.CUSTOMER.getName()).append(":")
                .append(statisticsUsers.stream().filter(o->StatisticsEnum.platform.MALL.getCode()==o.getPlatform())
                        .mapToInt(e-> e.getCustomerCount()==null?0:e.getCustomerCount()).sum()).append(",")
                //app:注册用户
                .append(StatisticsEnum.platform.APP.getName()).append(":")
                .append(StatisticsEnum.UserStyle.REGISTER.getName()).append(":")
                .append(statisticsUsers.stream().filter(o->StatisticsEnum.platform.APP.getCode()==o.getPlatform())
                        .mapToInt(e-> e.getRegisterUserCount()==null?0:e.getRegisterUserCount()).sum()).append(",")
                //app:活跃用户
                .append(StatisticsEnum.platform.APP.getName()).append(":")
                .append(StatisticsEnum.UserStyle.ACTIVE.getName()).append(":")
                .append(statisticsUsers.stream().filter(o->StatisticsEnum.platform.APP.getCode()==o.getPlatform())
                        .mapToInt(e-> e.getActiveUserCount()==null?0:e.getActiveUserCount()).sum()).append(",")
                //app:游客
                .append(StatisticsEnum.platform.APP.getName()).append(":")
                .append(StatisticsEnum.UserStyle.CUSTOMER.getName()).append(":")
                .append(statisticsUsers.stream().filter(o->StatisticsEnum.platform.APP.getCode()==o.getPlatform())
                        .mapToInt(e-> e.getCustomerCount()==null?0:e.getCustomerCount()).sum()).append(",")
                .append(",成交金额数据统计:,")
                //小程序:微信:商品
                .append(StatisticsEnum.platform.MALL.getName()).append(":")
                .append(StatisticsEnum.payType.WXPAY.getName()).append(":")
                .append(StatisticsEnum.orderStyle.ORDER.getName()).append(":")
                .append(statisticsAmounts.stream().filter(o->StatisticsEnum.platform.MALL.getCode()==o.getPlatform()&&StatisticsEnum.payType.WXPAY.getCode()==o.getPayType()&&StatisticsEnum.orderStyle.ORDER.getCode()==o.getOrderStyle())
                        .map(StatisticsAmountVo::getTotalAmounts).reduce(BigDecimal.ZERO,BigDecimal::add).toString()).append(",")
                //app:微信:商品
                .append(StatisticsEnum.platform.APP.getName()).append(":")
                .append(StatisticsEnum.payType.WXPAY.getName()).append(":")
                .append(StatisticsEnum.orderStyle.ORDER.getName()).append(":")
                .append(statisticsAmounts.stream().filter(o->StatisticsEnum.platform.APP.getCode()==o.getPlatform()&&StatisticsEnum.payType.WXPAY.getCode()==o.getPayType()&&StatisticsEnum.orderStyle.ORDER.getCode()==o.getOrderStyle())
                        .map(StatisticsAmountVo::getTotalAmounts).reduce(BigDecimal.ZERO,BigDecimal::add).toString()).append(",")
                //app:微信:话费
                .append(StatisticsEnum.platform.APP.getName()).append(":")
                .append(StatisticsEnum.payType.WXPAY.getName()).append(":")
                .append(StatisticsEnum.orderStyle.MOBILE.getName()).append(":")
                .append(statisticsAmounts.stream().filter(o->StatisticsEnum.platform.APP.getCode()==o.getPlatform()&&StatisticsEnum.payType.WXPAY.getCode()==o.getPayType()&&StatisticsEnum.orderStyle.MOBILE.getCode()==o.getOrderStyle())
                        .map(StatisticsAmountVo::getTotalAmounts).reduce(BigDecimal.ZERO,BigDecimal::add).toString()).append(",")
                //app:支付宝:商品
                .append(StatisticsEnum.platform.APP.getName()).append(":")
                .append(StatisticsEnum.payType.ALIPAY.getName()).append(":")
                .append(StatisticsEnum.orderStyle.ORDER.getName()).append(":")
                .append(statisticsAmounts.stream().filter(o->StatisticsEnum.platform.APP.getCode()==o.getPlatform()&&StatisticsEnum.payType.ALIPAY.getCode()==o.getPayType()&&StatisticsEnum.orderStyle.ORDER.getCode()==o.getOrderStyle())
                        .map(StatisticsAmountVo::getTotalAmounts).reduce(BigDecimal.ZERO,BigDecimal::add).toString()).append(",")
                //app:支付宝:话费
                .append(StatisticsEnum.platform.APP.getName()).append(":")
                .append(StatisticsEnum.payType.ALIPAY.getName()).append(":")
                .append(StatisticsEnum.orderStyle.MOBILE.getName()).append(":")
                .append(statisticsAmounts.stream().filter(o->StatisticsEnum.platform.APP.getCode()==o.getPlatform()&&StatisticsEnum.payType.ALIPAY.getCode()==o.getPayType()&&StatisticsEnum.orderStyle.MOBILE.getCode()==o.getOrderStyle())
                        .map(StatisticsAmountVo::getTotalAmounts).reduce(BigDecimal.ZERO,BigDecimal::add).toString()).append(",")
                .append(",成交单据数量:,")
                //商品订单
                .append(StatisticsEnum.orderStyle.ORDER.getName()).append(":")
                .append(statisticsOrders.stream().filter(o->StatisticsEnum.orderStyle.ORDER.getCode()==o.getOrderStyle())
                        .mapToInt(e-> e.getOrderCount()==null?0:e.getOrderCount()).sum()).append(",")
                //话费订单
                .append(StatisticsEnum.orderStyle.MOBILE.getName()).append(":")
                .append(statisticsOrders.stream().filter(o->StatisticsEnum.orderStyle.MOBILE.getCode()==o.getOrderStyle())
                        .mapToInt(e-> e.getOrderCount()==null?0:e.getOrderCount()).sum()).append(",")
                .append(",发送短信数量:").append(statisticsVo.getSmsCount());
        //具体需要提醒的人的电话,","分隔
        String mobiles="";
        gateApi.dingTalkMessage(message.toString(),mobiles);
    }

    public StatisticsVo test() {
        StatisticsVo statisticsVo=new StatisticsVo();
        /**
         * 1，每日注册用户数（区分小程序和app）
         * 每日活跃用户数（区分小程序和app，区分正常用户，访客）
         */
        List<StatisticsUserVo> statisticsUserVos = queryStatisticsUserNew();
        List<StatisticsUserVo> statisticsUserVos1 = queryActiveUserNew();
        List<StatisticsUserVo> statisticsUsers=new ArrayList<>();
        //小程序
        StatisticsUserVo statisticsUserVo=new StatisticsUserVo();
        statisticsUserVo.setPlatform(0);
        statisticsUserVo.setRegisterUserCount(0);
        if (!CollectionUtils.isEmpty(statisticsUserVos)){
            statisticsUserVos.stream().forEach(o -> {
                if (o.getPlatform()==0){
                    statisticsUserVo.setRegisterUserCount(o.getRegisterUserCount());
                }
            });
        }
        if(!CollectionUtils.isEmpty(statisticsUserVos1)){
            statisticsUserVos1.stream().forEach(o -> {
                if (o.getPlatform()==0){
                    statisticsUserVo.setCustomerCount(o.getCustomerCount());
                    statisticsUserVo.setActiveUserCount(o.getActiveUserCount());
                }
            });
        }
        statisticsUsers.add(statisticsUserVo);
        //app
        StatisticsUserVo statisticsUserVo2=new StatisticsUserVo();
        statisticsUserVo2.setPlatform(1);
        statisticsUserVo2.setRegisterUserCount(0);
        if (!CollectionUtils.isEmpty(statisticsUserVos)){
            statisticsUserVos.stream().forEach(o -> {
                if (o.getPlatform()==1){
                    statisticsUserVo2.setRegisterUserCount(o.getRegisterUserCount());
                }
            });

        }
        if (!CollectionUtils.isEmpty(statisticsUserVos1)){
            statisticsUserVos1.stream().forEach(o -> {
                if (o.getPlatform()==1){
                    statisticsUserVo2.setActiveUserCount(o.getActiveUserCount());
                    statisticsUserVo2.setCustomerCount(o.getCustomerCount());
                }
            });
        }
        statisticsUsers.add(statisticsUserVo2);
        statisticsVo.setStatisticsUsers(statisticsUsers);
        return  statisticsVo;
    }
}
